Add reference counting to the babl library
authorØyvind Kolås <ok@src.gnome.org>
Tue, 23 Aug 2005 07:41:51 +0000 (07:41 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Tue, 23 Aug 2005 07:41:51 +0000 (07:41 +0000)
ChangeLog
babl/babl.c

index 355055597c37274e3db1f9baca0efc6a3ac6ba5d..b5f82d98bc2765207a3981d1d6307b9ac5f2ac07 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-08-22  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl.c: implement ref counting to avoid unneccesary destruction
+       of static data when multiple instances of babl is used in an
+       adressspace.
+
+2005-08-23  Øyvind Kolås  <pippin@gimp.org>
+
+       * tests/Makefile.am:
+       * tests/babl_class_name.c: new test.
+
 2005-08-22  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-classes.h: (BabPixelFormat): only a single BablModel.
index a19477f7ecabb70ec9c584c8a8d51f0beb4e016e..ddbc1bd5fbc0ed65f3e4c010b5e2a60dc2d4e588 100644 (file)
 #include "babl-sanity.h"
 #include "babl-introspect.h"
 
+static int ref_count=0;
+
 void
 babl_init (void)
 {
-  babl_type_init ();
-  babl_sampling_init ();
-  babl_component_init ();
-  babl_model_init ();
-  babl_pixel_format_init ();
-  babl_conversion_init ();
-  babl_base_init ();
-
-  babl_sanity ();
+  if (ref_count++==0)
+    {
+      babl_type_init ();
+      babl_sampling_init ();
+      babl_component_init ();
+      babl_model_init ();
+      babl_pixel_format_init ();
+      babl_conversion_init ();
+      babl_base_init ();
+      babl_sanity ();
+    }
 }
 
 void
 babl_destroy (void)
 {
-  /* babl_base is destroy by the containing types */
-
-  babl_fish_destroy ();
-  babl_conversion_destroy ();
-  babl_pixel_format_destroy ();
-  babl_model_destroy ();
-  babl_component_destroy ();
-  babl_sampling_destroy ();
-  babl_type_destroy ();
+  /* babl_base is destroyed by the containing types */
 
-  babl_memory_sanity ();
+  if (!--ref_count)
+    {
+      babl_fish_destroy ();
+      babl_conversion_destroy ();
+      babl_pixel_format_destroy ();
+      babl_model_destroy ();
+      babl_component_destroy ();
+      babl_sampling_destroy ();
+      babl_type_destroy ();
+      babl_memory_sanity ();
+    }
 }